package com.wpzf.ndhc.service.impl;


import com.wpzf.ndhc.utils.TableUtil;
import com.wpzf.ndhc.mapper.WpzfNdhcShemeMapper;
import com.wpzf.ndhc.service.WpzfNdhcShemeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class WpzfNdhcShemeServiceImpl implements WpzfNdhcShemeService
{

    @Autowired
    WpzfNdhcShemeMapper wpzfNdhcShemeMapper;

    @Override
    public List<Map<String, Object>> getNdhcyear() {
        return wpzfNdhcShemeMapper.getNdhcyear();
    }

    @Override
    public List<Map<String, Object>> getSchemeInfo(Map<String, Object> parm) {
        return wpzfNdhcShemeMapper.getSchemeInfo(parm);
    }

    @Override
    public Map<String, Object> getSchemeInfobypch(Map<String, Object> parm) {
        return wpzfNdhcShemeMapper.getSchemeInfobypch(parm);
    }

    @Override
    public int saveScheme(Map<String, Object> parm) {
        return wpzfNdhcShemeMapper.updateSheme(parm);
    }

    @Override
    public int extract(Map<String, Object> parm)
    {
        int count=0;
       //按照规则抽取
        Map<String, Object> model=wpzfNdhcShemeMapper.getSchemeInfobypch(parm);
        if(model!=null)
        {
            //model = TableUtil.TableName(model);
            if(("1").equals(model.get("status").toString()))
            {
                return  -1;
            }
            //填报地块其中耕地面积
            String gdmj=model.get("gdmj").toString();
            if(!("").equals(gdmj))
            {
                double gdmjd = Double.valueOf(gdmj);
                model.replace("gdmj",gdmjd);
                count+=wpzfNdhcShemeMapper.insertbygdmj(model);
            }
            //建设用地面积
            String jsydmj=model.get("jsydmj").toString();   //查找相关得图斑
            if(!("").equals(jsydmj))
            {
                double jsydmjd = Double.valueOf(jsydmj);
                model.replace("jsydmj",jsydmjd);
                count+=wpzfNdhcShemeMapper.insertbyjsydmj(model);
            }
            //未利用地面积
            String wlydmj=model.get("wlydmj").toString();
            if(!("").equals(wlydmj))
            {
                double wlydmjd = Double.valueOf(wlydmj);
                model.replace("wlydmj",wlydmjd);
                count+=wpzfNdhcShemeMapper.insertbywlydmj(model);
            }
            //其他农用地面积
            String qtnydmj=model.get("qtnydmj").toString();
            if(!("").equals(qtnydmj))
            {
                double qtnydmjd = Double.valueOf(qtnydmj);
                model.replace("qtnydmj",qtnydmjd);
                count+=wpzfNdhcShemeMapper.insertqtnydmj(model);
            }
            //地块面积
            String dkmj=model.get("dkmj").toString();
            if(!("").equals(dkmj))
            {
                double dkmjd = Double.valueOf(dkmj);
                model.replace("dkmj",dkmjd);
                count+=wpzfNdhcShemeMapper.insetdkmj(model);
            }
            //整改落实到位情况
//            String zglsdwqk=model.get("zglsdwqk").toString();
//            if(!("").equals(zglsdwqk))
//            {
//                count+=wpzfNdhcShemeMapper.updateDkxxbbyzglsdwqk(model);
//            }
            //更新状态 证明抽取完成
            wpzfNdhcShemeMapper.updateShemestatus(parm);
        }
        return  count;

    }
}
